﻿<Page x:Class="EduAssess.Views.TestPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      mc:Ignorable="d"
      DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=TestPageViewModel}"
      Title="TestPage" Height="450" Width="800">
    <Page.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </Page.Resources>
    <ScrollViewer >
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>

            <TextBlock Text="{Binding QuestionNumber, StringFormat={} Вопрос {0}}"
                       Margin="150,20"
                       Background="Transparent"/>
            <StackPanel Grid.Row="0" Margin="150,20,135,20">
                <TextBlock Text="{Binding CurrentQuestion.Name}"
                           TextWrapping="Wrap"
                           Padding="2"
                           TextAlignment="Left"/>
                <ItemsControl ItemsSource="{Binding CurrentQuestion.Answers}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <WrapPanel Orientation="Horizontal">
                                <RadioButton
                                    GroupName="{Binding RelativeSource={RelativeSource AncestorType=Border}, Path=DataContext.CurrentQuestion.Id}"
                                             Padding="2"
                                             IsChecked="{Binding IsTrue}"
                                             IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=Border}, Path=DataContext.IsEnabled}">
                                    <TextBlock
                                        Text="{Binding Name}"
                                        TextWrapping="Wrap"
                                        TextAlignment="Left">
                                    </TextBlock>
                                </RadioButton>
                                </WrapPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>

            
                <StackPanel Grid.Row="0" Margin="150,20,150,20">
                    <TextBlock Text="{Binding CorrectAnswer.Name, StringFormat={}Ответ: {0}}"
                               TextWrapping="Wrap"
                               Padding="2"
                               TextAlignment="Left"/>
                </StackPanel>

            <Button Content="Проверить"
                    Grid.Row="4"
                    Margin="5"
                    Padding="5"
                    HorizontalAlignment="Center"
                    Width="200"
                    Command="{Binding CheckAnswerCommand}"
                    Visibility="{Binding CanCheckAnswer, Converter = {StaticResource BooleanToVisibilityConverter}}"/>

            <Button Content="Следующий вопрос"
                    Grid.Row="5"
                    HorizontalAlignment="Center"
                    Width="200"
                    Padding="5"
                    Command="{Binding NextQuestionCommand}"/>

            <Button Content="Предыдущий вопрос"
                    Grid.Row="6"
                    HorizontalAlignment="Center"
                    Width="200"
                    Padding="5"
                    Command="{Binding PreviousQuestionCommand}"
                    Visibility="{Binding ShowPreviousButton, Converter = {StaticResource BooleanToVisibilityConverter}}">
            </Button>

            <UniformGrid Columns="2"
                         Grid.Row="8"
                         Margin="50,5">
                <Button Content="Результаты"
                        Margin="70,10"
                        Padding="5"
                        FontSize="16"
                        Command="{Binding ShowResultsCommand}"/>
                <Button Content="Покинуть тест"
                        Margin="70,10"
                        Padding="5"
                        FontSize="16"
                        Command="{Binding LeaveTestCommand}"/>

            </UniformGrid>
        </Grid>
    </ScrollViewer>
</Page>
